package com.atguigu.distributed.lock.leecode;

/**
 * 判断一个正整数是否是2的整数次幂
 *
 */
public class IsPowerOf2 {
    public static boolean isPowerOf2(int num){
        int temp=1;
        while (temp<=num){
            if(temp==num){
                return true;
            }
            temp*=2;

        }
        return false;
    }
    public static boolean isPower2(int num){
        int temp = 1;
        while (temp<=num){
            if (temp==num){
                return true;
            }
            temp*=2;
        }
        return false;
    }
    public static boolean isPowerOf2V2(int num){
        return (num&num-1)==0;
    }
    public static boolean isPowerOf3(int num){
        return (num&num-1)==0;
    }

    public static void main(String[] args) {
        System.out.println(isPowerOf2(65));
        System.out.println(isPowerOf2V2(64));
    }
}
